package com.course.controller;

import com.course.entity.ResultBody;
import com.course.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/grade")
@CrossOrigin(origins = "*")
public class GradeController {
    @Autowired
    private GradeService gradeService;
    @RequestMapping("/addgrade")
    public ResultBody addgrade(@RequestBody Map<String,Object> map){
       if(map.get("name")==null||map.get("score")==null||map.get("coursename")==null||map.get("usernumber")==null||map.get("class")==null||map.get("usercollege")==null)
       {
           return new ResultBody(404,"缺少参数",false);
       }
       return gradeService.addgrade(map);
    }
    @RequestMapping("/displaygrade")
    public ResultBody displaygrade(){
        return gradeService.displaygrade();
    }
    @RequestMapping("/delgrade")
    public ResultBody delgrade(@RequestBody Map<String,Object> map){
        if(map.get("id")==null)
        {
            return new ResultBody(404,"参数错误",false);
        }
        return gradeService.delgrade(map);
    }
    @RequestMapping("updategrade")
    public ResultBody updategrade(@RequestBody Map<String,Object> map){
        if(map.get("id")==null&&map.get("name")==null&&map.get("score")==null&&map.get("coursename")==null&&map.get("usernumber")==null&&map.get("class")==null&&map.get("coursecollege")==null)
        {
            return new ResultBody(404,"缺少参数",false);
        }
        return gradeService.updategrade(map);
    }
}
